package com.ycz.master.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ycz.master.mapper.EmpMapper;
import com.ycz.master.pojo.Emp;
import com.ycz.master.pojo.EmpAndEmpTypeAndDept;
import com.ycz.master.service.EmpServcie;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * author zyc
 * Created on 2021/9/30 13:19
 */
@Service
public class EmpServcieImpl extends ServiceImpl<EmpMapper, Emp> implements EmpServcie {
    @Autowired
    public EmpMapper mapper;

    @Override
    public Emp login(String account, String password) {
        QueryWrapper<Emp> wrapper = new QueryWrapper<>();
        wrapper.eq("account", account).eq("password", password);
        Emp emp = mapper.selectOne(wrapper);
        if (emp != null) {
            return emp;
        } else {
            return null;
        }
    }

//    @Override
//    public List<Emp> findallemp() {
//        return mapper.selectList(null);
//    }
    @Override
    public List<EmpAndEmpTypeAndDept> findallemp() {
//        System.out.println(mapper.selectAllEmp());
        return mapper.selectAllEmp();
    }
    @Override
    public Emp findById(Integer id) {
        return mapper.selectById(id);
    }

    @Override
    public Boolean updataemp(Emp emp) {
        UpdateWrapper<Emp> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("emp_id", emp.getEmpId());
        int update = mapper.update(emp, updateWrapper);
//        System.out.println(update);
        if (update == 1) {
            return true;
        }
        return false;
    }

    //更改密码
    @Override
    public Boolean change(String account, String password, String oldpassword) {
        UpdateWrapper<Emp> wrapper = new UpdateWrapper<>();
        wrapper.eq("account", account).eq("password", oldpassword).set("password", password);
        int update = mapper.update(null, wrapper);
        System.out.println(update);
        if (update == 1) {
            return true;
        }
        return false;
    }

    @Override
    public int insertemp(Emp emp) {
        return mapper.insert(emp);
    }
}
